----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 13010 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Bloodbolt"
SPELL.m_sToolTip =	[[Launch a ball of molten
					  rock at the target, dealing
					  35 fire damage.]]
SPELL.m_sIcon = "devin/blackbetty/spells/lifebinder/bloodbolt.png"
SPELL.m_iCoolDown = 1.5
SPELL.m_iManaCost = 0
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_MAGICDAMAGE
SPELL.m_bRecastWhileCasting = false


---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	local weapon = nil
	local target = nil
	
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
		target = pl:GetNetworkedEntity("Target")
	else
		target = pl.Target
	end
	
	local range = self.m_iRange
	if(target && target:IsValid() && target != pl) then
		pl.InSpellAnimation = true
		pl:EmitSound("devin/blackbetty/player/male/swing_common"..math.random(1,3)..".wav", 100, 100+math.random(-1, -5))
		pl:EmitSound("devin/blackbetty/weapons/slam/swing_"..math.random(1,3)..".wav", 160, 100+math.random(20,30))
		ParticleEffectAttach( "blood_hands_instacast", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("rightfoot"))
			
		if(target and pl:GetPos():Distance(target:GetPos()) < self.m_iRange)then
			if(SERVER)then
				timer.Simple(0.1, function() 
					local hitdelay = ((pl:GetPos() - target:GetPos()):Length()/1600)
					pl:EmitSound("devin/blackbetty/weapons/castsounds/ShadowCast.wav", 80, 100+math.random(-10,10))
					--pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_SLAM)
					if(pl:IsPlayer())then
						pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_SLAM)
					else
						pl:RestartGesture(ACT_HL2MP_GESTURE_RANGE_ATTACK_SLAM)
					end
					local myhitdelay = ((pl:GetPos() - target:GetPos()):Length()/1800)
					ParticleEffect( "pummel_hit", pl:GetPos() + (pl:GetAngles():Forward()*48) + Vector(0, 0, 45) + (pl:GetAngles():Right()*16), Angle(0,0,0), pl )
					LaunchProjectile(pl, target, 0, "pummel_hit", "", "blood_hands", "ambient/atmosphere/city_tone.wav", myhitdelay, 1300, "models/crossbow_bolt.mdl")
					timer.Simple(hitdelay, function()
						local dmginfo = DamageInfo()
							if(weapon)then
								dmginfo:SetDamage( math.random(weapon.MinWeaponDamage, weapon.MaxWeaponDamage) )
							else
								dmginfo:SetDamage( math.random(pl.MinDamage, pl.MaxDamage) ) 
							end
							dmginfo:SetDamageType( DMG_GENERIC ) 
							dmginfo:SetAttacker( pl )
						target:TakeDamageInfo( dmginfo )
						if(pl:IsPlayer())then
							UpdatePlayerResource(pl, 5)
						end
						target:EmitSound("devin/blackbetty/weapons/RendTarget.wav", 140, 100+math.random(-10,10))
						ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 45), Angle(0,0,0), target )
					end)
				end)
			end
		end
		timer.Simple(0.3, function()
			pl.InSpellAnimation = false
			pl:SetNWBool("Casting", false)
			pl:SetNWBool("Casted", false)
		end)
	end
end




